<template>
    <div id="te">
    <div v-if="isShow == true">
        <!-- <i class="el-icon-edit"  style="position: fixed;top: 408px;right: 16px;" @click="audit"></i> -->
        <el-button @click="audit" icon="el-icon-edit" type="primary" style="position: fixed;top: 408px;right: 16px;font-size:20px" circle></el-button>
        <el-button @click="clearCanvas" icon="el-icon-refresh" style="position: fixed;top: 458px;right: 16px;font-size:20px" type="warning" circle></el-button>
        <el-button @click="isShow = false" icon="el-icon-close" style="position: fixed;top: 506px;right: 16px;font-size:20px" type="danger" circle></el-button>
    </div>

    <el-table
        :data="resumeList"
        style="width: 100%">
        <el-table-column
            prop="id"
            label="ID"
            width="180">
        </el-table-column>
        <el-table-column
            prop="name"
            label="姓名"
            width="180">
        </el-table-column>
        <el-table-column
            label="地址">
            <template slot-scope="obj">
                {{editHopePositionId(obj.row.address,1)}}
            </template>
        </el-table-column>
        <el-table-column
            prop="sex"
            label="性别">
        </el-table-column>
        <el-table-column
            prop="phone"
            label="手机号">
        </el-table-column>
        <el-table-column
            prop="email"
            label="邮箱">
        </el-table-column>
        <el-table-column
            prop="status"
            label="状态">
          <template slot-scope="obj">
            <span v-if="obj.row.status == 0">待审核</span>
            <span v-if="obj.row.status == 1">已通过</span>
            <span v-if="obj.row.status == 2">已驳回</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
            <el-button
            size="mini"
            @click="lookResume(scope.$index, scope.row)">查看简历</el-button>
        </template>
    </el-table-column>
        </el-table>
        <div ref="printMe">
        <!--弹跳狂-->


        <!-- <el-dialog
        title="学生简历预览"
        :visible.sync="dialogVisible"
        width="30%"
        @close="clearReason"
        > -->
<div v-if="isShow == true"  ref="printMe">
    <el-card style="height: 40%;width: 100%">
      <span style="color:#426F42;font-weight:700">个人基本信息：</span><br><br>
       姓名:{{resumeDao.name}}  <font style="margin-left:102px">性别:{{resumeDao.sex}}</font><br>
           手机号:{{resumeDao.phone}}  <font style="margin-left:30px">地址:{{resumeDao.address}}</font><br><br>
         <span style="color:#426F42;font-weight:700"> 个人优势：</span><br>
        <div
         v-for="item in advangeDao"
         :key="item.id"
         >
            {{item.content}}
        </div>
        <br>
        <br>
        <span style="color:#426F42;font-weight:700"> 求职期望:</span>
        <div
         v-for="item in hopeDao"
         :key="item.id"
         >
           期望职位: {{editHopePositionId(item.hopePositionId,0)}}
           期望城市: {{editHopePositionId(item.hopeAddressId,1)}}
           期望薪资: {{editHopePositionId(item.hopeSalaryId,2)}}
        </div>
        <br>
        <br>
         <span style="color:#426F42;font-weight:700"> 工作经历</span><br>
        <div
         v-for="item in workDao"
         :key="item.id"
         >
           名称 {{item.name}} <font style="margin-left:102px">部门:{{item.department}}</font><br>
           行业:{{item.industry}}
           
           <font style="margin-left:110px">类型:{{editHopePositionId(item.type,0)}}</font><br>
           开始时间:{{editDateTime(item,item.inDate)}}
           <font style="margin-left:10px">结束时间:{{editDateTime(item,item.outDate)}}</font><br>
           项目名称:{{item.positionName}}
           <br>
           简介:{{item.content}}
        </div>
        <br>
        <br>
         <span style="color:#426F42;font-weight:700">项目经历:</span>
        <br>
        <div
         v-for="item in itemDao"
         :key="item.id"
         ><br>
           项目名称:{{item.itemName}}
           <font style="margin-left:90px">
           公司名称:{{item.companyName}}</font><br>
           开始时间:{{editDateTime(item,item.itemInDate)}}
           <font style="margin-left:60px">
           结束时间:{{editDateTime(item,item.itemOutDate)}}
           </font><br>
           项目网址:{{item.itemUrl}}<br>
           项目描述:{{item.itemDesc}}
           成就:{{item.achievement}}
        </div>
            <br> <br>
         <span style="color:#426F42;font-weight:700"> 教育经历:</span>
        <br>
        <div
         v-for="item in educationDao"
         :key="item.id"
         >
          学校名称 {{item.schoolName}}<font style="margin-left:15px;margin-right:15px">学历:{{item.education}}</font>
            专业:{{item.majorName}}<br>
           开始时间:{{editDateTime(item,item.schoolInDate)}}
           结束时间:{{editDateTime(item,item.schoolOutDate)}}
            

        </div>
        <br>
        <br>
          <span style="color:#426F42;font-weight:700">社交主页:</span>
         <br>
        <div
         v-for="item in socialDao"
         :key="item.id"
         >
        网址{{item.httpUrl}}

        </div>
        <br>
        <br>
          <span style="color:#426F42;font-weight:700">设计作品:</span>
         <br>
        <div
         v-for="item in imageDao"
         :key="item.id"
         >
        图片展示:{{item.mageUrl}}

        </div>
          <span v-if="resumeDao.status!=0" style="color: #00b7ee">{{examineDao.reason}}</span>
          <el-input
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4}"
            placeholder="驳回原因"
            v-model="examineDao.reason" v-if="resumeDao.status==0">
          </el-input>
        <div style="margin: 20px 0;"></div>
        <!-- <el-button size="mini" @click="dialogVisible = false">取 消</el-button> -->
        <el-button
          size="mini"
          type="success"
          @click="examinerResume(1)" v-if="resumeDao.status==0">通过</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="examinerResume(2)" v-if="resumeDao.status==0">驳回</el-button>
          
      <!-- </el-dialog> -->
    </el-card>
</div>
    <span slot="footer" class="dialog-footer" v-if="isShow == true">
        <paint ref="paint"></paint>
    </span>
      </div>
    </div>
</template>
<script>

import imageVue from './image.vue';
import moment from 'moment';
import paint from './paint.vue'
export default {
    name:'Te',
    components:{
      paint
    },
    data(){
        return{
          resumeList:[],
          teacherid:null,
          teObject:{},
          clazz:{},
          clazzid:null,
          resumeDao:[],
          advangeDao:[],
          workDao:[],
          hopeDao:[],
          educationDao:[],
          itemDao:[],
          examineDao:{},
          socialDao:[],
          imageDao:[],
          dialogVisible:false,
          minSalaryOptions: [],//最低薪资
          maxSalaryOptions: [],//最低薪资
          addressOptionsOne: [],//城市全部数据
          positionOptionsOne: [],//职位全部数据,
          //简历id
          resumeId:'',
          isShow:false
        }
    },
    methods: {
        editDateTime(row,column){//日期格式处理
            const date = column
            if (date === undefined) {
                return ''
            }
            return moment(date).format('yyyy-MM-DD')
        },
        editHopePositionId(val,status){//数据转码
            if (status===0){
                val = JSON.parse(val);
                val = val[val.length-1];
                for (let i=0;i<this.positionOptionsOne.length;i++){
                let data = this.positionOptionsOne[i];
                if (data.id===val){
                    return data.name;
                }
                }
            }
            if (status===1){
                val = JSON.parse(val);
                val = val[val.length-1];
                for (let i=0;i<this.addressOptionsOne.length;i++){
                let data = this.addressOptionsOne[i];
                if (data.id===val){
                    return data.address;
                }
                }
            }
            if (status===2){
                val = JSON.parse(val);
                let resultData = '';
                let valOne = val[0];
                let valTwo = val[1];
                for (let i=0;i<this.minSalaryOptions.length;i++){
                let data = this.minSalaryOptions[i];
                if (data.id===valOne){
                    resultData += data.money + "-";
                }
                }
                for (let i=0;i<this.minSalaryOptions.length;i++){
                let data = this.minSalaryOptions[i];
                if (data.id===valTwo){
                    resultData += data.money;
                }
                }
                return resultData;
            }
        },
        async findClazzByTeacherId(){
            this.teObject=JSON.parse(localStorage.getItem("user"));
            this.teacherid=this.teObject.userId;

            this.$http({
                url:this.$http.adornUrl(`/sys/clazz/findClazzByTeacherId/${this.teacherid}`),
                method: 'get',

            }).then(({data}) => {
                this.clazzid = data.id;

                this.findResumeByClazzId();
            })

            await this.$http({
                url: this.$http.adornUrl('/hope/position'),
                method: 'get'
            }).then(({data}) => {
                this.positionOptionsOne = data;
            })
            await this.$http({
                url: this.$http.adornUrl('/hope/address'),
                method: 'get'
            }).then(({data}) => {
                this.addressOptionsOne = data;
            })
            await this.$http({
                url: this.$http.adornUrl('/hope/minsalary'),
                method: 'get'
            }).then(({data}) => {
                this.minSalaryOptions = data
                this.maxSalaryOptions = data
                this.maxSalaryOptions[this.maxSalaryOptions.length-1] = {id:100,money:'100k'}
            })
        },
        //根据班级找对应的简历基本表
        findResumeByClazzId(){

             this.$http({
                    url:this.$http.adornUrl(`/resume/resumebasic/findResumeByClazzId/${this.clazzid}`),
                    method: 'get',

                }).then(({data}) => {

                this.resumeList = data
            })
        },
        //查看简历
        lookResume(index,row){
             this.resumeId=row.id;
            localStorage.setItem("resumeId",this.resumeId);
             this.$http({
                    url:this.$http.adornUrl(`/resume/resumebasic/findAll/${row.id}`),
                    method: 'get',
                }).then(({data}) => {
                    this.resumeDao = data.resumeBasic;
                    this.resumeDao.address = this.editHopePositionId(this.resumeDao.address,1)
                    this.advangeDao=data.advantage
                   this.workDao=data.work
                   this.hopeDao=data.hope
                   this.educationDao=data.education
                    this.itemDao=data.item
                    this.socialDao=data.socil
                    this.imageDao=data.image
                    if(data.examine.reason==null){
                      this.examineDao.reason=undefined
                    }else{
                      this.examineDao.reason=data.examine.reason
                    }
                    this.isShow=true;
            })
            //this.dialogVisible=true;
        },
        //清空驳回原因
        clearReason(){
          this.examineDao.reason = null
        },
        //审核简历
        examinerResume(status){
                console.log(status,this.examineDao.reason)
               var image= location.getItem("image");
                var reason
                if(this.examineDao.reason==undefined){
                  reason = null
                }
                this.$http({
                    url:this.$http.adornUrl(`/resume/resumebasic/updateStatus?id=${this.resumeId}&status=${status}&reason=${reason}&image=${image}`),
                    method: 'get',

                }).then(({data}) => {

               if(data.message=='1'){
                 alert(data.fail)
               }else{
                 this.dialogVisible = false
                 this.findClazzByTeacherId()
               }
            })
        },
        async audit(){
            const el = this.$refs.printMe;
            const options = {
            type: 'dataURL'
            }
            let output = await this.$html2canvas(el, options);
            this.$refs.paint.drawImage(output,el.offsetWidth, el.offsetHeight);
        },
        clearCanvas(){
            this.$refs.paint.initCanvas();
            this.audit();
        },
    },
    mounted(){
        this.findClazzByTeacherId();
    }
}
</script>

